//
//  SCAppMacro.h
//  Shuaiche
//
//  Created by zzs on 2017/10/25.
//  Copyright © 2017年 zzs. All rights reserved.
//

#ifndef SCAppMacro_h
#define SCAppMacro_h


#pragma mark -
#pragma mark - Device Info

//#define kDevice_Is_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

#define kDevice_Is_iPhoneX \
({BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isPhoneX);})

#define kiPhoneXTabBarHeight 83
#define kiPhoneDefaultTabBarHeight 49
#define kiPhoneXInsetTop 88
#define kiPhoneDefaultInsetTop 64

#define WINDOW_WIDTH [UIScreen mainScreen].bounds.size.width

#define WINDOW_HEIGHT ([UIScreen mainScreen].bounds.size.height)

#define APP_KEYWINDOW [UIApplication sharedApplication].keyWindow

#define ROOT_VC [UIApplication sharedApplication].keyWindow.rootViewController

#define STATUSBAR_HEIGHT [[UIApplication sharedApplication] statusBarFrame].size.height

#define NAVIGATIONBAR_HEIGHT self.navigationController.navigationBar.frame.size.height

#define TABBAR_HEIGHT self.tabBarController.tabBar.frame.size.height

#pragma mark - 
#pragma mark - Global macros

#define kIsLogin @"isLogin" //Login:YES, Logout/Relaunch:NO
#define kIsRegister @"isRegister" //是否注册公司信息
#define kSessionId @"sessionId"
#define kUsername @"phone"
#define kUserId @"userId"

#define kApp_Splash_Version @"splashversion"
#define kAppNewestVersion @"appNewestVersion"

#pragma mark - 
#pragma mark - 网络请求

#define API_IMAGE_LIST_TYPE @"?x-oss-process=style/carpic_list"
#define API_IMAGE_SMALL_TYPE @"?x-oss-process=style/carpic_small"
#define API_IMAGE_THUMB_TYPE @"?x-oss-process=style/carpic_thumb"
#define API_IMAGE_WATER_TYPE @"?x-oss-process=style/logo_waterprint"
#define API_IMAGE_780_TYPE @"?x-oss-process=style/w780"

//#define APP_PRO_MODE 1  //正式环境
//#define APP_PRE_REL_MODE 1 //预发布环境
//#define APP_TEST_MODE 1 //测试环境
//#define APP_DEV_MODE 1//开发环境


//#define API_IMG @"https://img.shuaiche.com"
//
//#if APP_DEV_MODE
//#define API_BASE @"https://api-dev.shuaiche.com"
//#define API_WEB  @"https://m-dev.shuaiche.com"
//
//#elif APP_PRO_MODE
//#define API_BASE @"https://api.shuaiche.com"
//#define API_WEB  @"https://m.shuaiche.com"
//
//#elif APP_TEST_MODE
//#define API_BASE @"https://api-test.shuaiche.com"
//#define API_WEB  @"https://m-test.shuaiche.com"
//#endif
//
//#define API_FORMAT(_DOMAIN_,_PATH_) ([_PATH_ hasPrefix:@"https://"] \
//        ? _PATH_        \
//        : ([_PATH_ hasPrefix:@"http://"]        \
//           ? [_PATH_ stringByReplacingOccurrencesOfString:@"http://" withString:@"https://"] \
//           :([_PATH_ hasPrefix:@"/"] \
//             ? [NSString stringWithFormat:@"%@%@",_DOMAIN_,_PATH_] \
//             : [NSString stringWithFormat:@"%@/%@",_DOMAIN_,_PATH_])))
//
//#define API_BASE_URL(URL)  API_FORMAT(API_BASE,URL)
//#define API_IMAGE_URL(URL) API_FORMAT(API_IMG,URL)

#define API_IMAGE_PROCESS_URL(_URL_,_TYPE_) [sc_url_img(_URL_) stringByAppendingString:_TYPE_]

#define API_WEB_URL(_URL_) ([_URL_ hasPrefix:@"https://"]?_URL_:[_URL_ hasPrefix:@"http://"]?_URL_:([_URL_ hasPrefix:@"/"]?[API_WEB stringByAppendingString:_URL_]:[API_WEB stringByAppendingFormat:@"/%@", _URL_]))
//TODO
#define API_SHOP_COMPANY_URL(_merchantId_,uid) [NSString stringWithFormat:@"%@/app/merchantpage?merchantId=%@&shareUserId=%@&shareMerchantId=%@",kSC_WEB_DOMAIN,_merchantId_,uid,_merchantId_]

#pragma mark - 
#pragma mark - 强弱引用
//weak－strong
#define WEAKSELF __weak typeof(self) weakSelf = self;
#define STRONGSELF __strong typeof(weakSelf) strongSelf = weakSelf;
#define Return_From_Block return;

#pragma mark -
#pragma mark - 单例声明
//单例函数声明
#define SINGLETON_FOR_DECLARAION(className) \
+(className*)shared##className;
//单例函数实现
#define SINGLETON_FOR_CLASS_IMPLEMENTATION(className) \
\
+ (className *)shared##className { \
static className *shared##className = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
shared##className = [[self alloc] init]; \
}); \
return shared##className; \
}

#pragma mark - 懒加载
// 可变数组
#define SC_M_Array(name) - (NSMutableArray *)name { \
    if (!_##name) { _##name = [NSMutableArray arrayWithCapacity:0];} return _##name;}

#define SC_M_Dictionary(name) - (NSMutableDictionary *)name { \
if (!_##name) { _##name = [NSMutableDictionary dictionaryWithCapacity:0];} return _##name;}

#define SC_Load_Nib(className) [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(className) owner:nil options:kNilOptions][0]

#ifdef DEBUG
#define NSLog(fmt, ...) NSLog((@"%s [Line %d] [%s] " fmt), __FUNCTION__, __LINE__, __TIME__,##__VA_ARGS__)
#else
#define NSLog(...)
#endif

#define SCColor(hex) [UIColor colorWithRed:((hex>>16)&0xff)/255. green:((hex>>8)&0xff)/255. blue:(hex&0xff)/255. alpha:1.0]

//#define RGBA(r,g,b,a) [UIColor colorWithRed:(r)/255.f green:(g)/255.f blue:(b)/255.f alpha:(a)]

#pragma mark -
#pragma mark - 二期测试

#define SecondPeriodDebug 0

#endif /* SCAppMacro_h */
